<?php

namespace App\Models\PrizePayment;

use App\Support\Database\Eloquent\UuidModel;

class PrizePayment extends UuidModel
{
    //支付状态 0未支付 1已提交支付 2支付取消 3支付成功 4 支付结束 5支付失败 6退款提交 7退款完成
    const PAY_UNPAID = 0;
    const PAY_COMMIT = 1;
    const PAY_CANCLE = 2;
    const PAY_SUCCESS = 3;
    const PAY_FINISH = 4;
    const PAY_FAIL = 5;
    const REFUND_COMMIT = 6;
    const REFUND_SUCCESS = 7;

    //支付方式 0支付宝 1微信
    const ALIPAY_METHOD = 0;
    const WECHAT_METHOD = 1;

    protected $guarded = array();

    public function prize()
    {
        return $this->belongsTo('\App\Models\Prize\Prize', 'prize_id', 'id');
    }

    public function isRemovable()
    {
        return $this->status != self::PAY_COMMIT && $this->status != self::REFUND_COMMIT;
    }

    public function isUnpaid()
    {
        return $this->status == self::PAY_UNPAID;
    }

    public function isCanceled()
    {
        return $this->status == self::PAY_CANCLE;
    }

    public function isPaid()
    {
        return $this->status == self::PAY_SUCCESS;
    }

    public function isCommit()
    {
        return $this->status == self::PAY_COMMIT;
    }

    public function isFailed()
    {
        return $this->status == self::PAY_FAIL;
    }

    public function revoke()
    {
        $this->status = self::PAY_UNPAID;
        return $this->save();
    }

    public function commited()
    {
        $this->status = self::PAY_COMMIT;
        return $this->save();
    }

    public function canceled()
    {
        $this->status = self::PAY_CANCLE;
        return $this->save();
    }

    public function paid()
    {
        $this->status = self::PAY_SUCCESS;
        return $this->save();
    }

    public function failed()
    {
        $this->status = self::PAY_FAIL;
        return $this->save();
    }
}
